package com.api.gbhg.daiyanlu.Dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;

/**
 * 海关医疗保险缴费经费
 * Mr.dyl
 */
public class SixteenDao {
    private static final Logger log= LoggerFactory.getLogger(SixteenDao.class);
    public RecordSetTrans getMainTable(String requestId){
        RecordSetTrans rts=new RecordSetTrans();
        StringBuffer sb=new StringBuffer();
        String sql ="select v.lcjlsqjlid, v.lcid,v.xmmin,v.sbdw,v.sbks,v.jbr,v.yszje,j.zfcgyswy,j.hwgz,j.gc,j.fw,j.xecg,j.requestId from uf_jingfei_version v \n" +
                "INNER JOIN uf_hgylbxjfjfxqbbb j on v.lcjlsqjlid =j.requestId where 1=1";
        sb.append(sql);
        try {
            if(!requestId.equals(" ")){
                sb.append(" AND j.requestId in ("+requestId+")");
            }else {
                return null;
            }
            //通过分页公式计算下一页在哪一行开始
            //如1，10，1-1 = 0，那第一条开始显示下面十条，第一页
            //如2，10，(2-1)乘以10 = 10，那就是第十条开始显示下面十条，第二页
            // 判断是mysql 还是sqlserver
//            pageNum=(pageNum-1)*pageSize;
//            if("sqlserver".equals(rts.getDBType())){
//                sb.append(" order by v.Id offset "+pageNum+" rows fetch next "+pageSize+" rows only");
//            }else if("mysql".equals(rts.getDBType())){
//                sb.append(" LIMIT "+pageNum+","+pageSize+"");
//            }
            log.info("海关医疗保险缴费经费主表sql:--->"+sb.toString());
            rts.executeQuery(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rts;
    }

    //获取数据条数
    public int getMainTableCount(String status){
        RecordSet rs = new RecordSet();
        String StrSQL ="select COUNT(1)AS num from uf_jingfei_version v INNER JOIN uf_hgylbxjfjfxqbbb b on v.lcjlsqjlid =b.requestId where 1=1";
        if(status.equals("3")){
            StrSQL=StrSQL+(" AND lcztz="+status);
        }else {
            StrSQL=StrSQL+(" AND lcztz<> 3");
        }
        log.info("海关医疗保险缴费经费总条数sql:--->"+StrSQL);
        rs.executeQuery(StrSQL);
        rs.next();
        return rs.getInt("num");
    }

    public RecordSet getDetailedTable(String requestid,int table){
        RecordSet rs = new RecordSet();
        String StrSQL="";
        if (table==1){
            StrSQL = "select * from uf_hgylbxjfjfxqbbb_dt1 where mainid="+"(select id from uf_hgylbxjfjfxqbbb where requestid=" + requestid+")"; //获取明细条1
        }else if (table==2){
            StrSQL = "select * from uf_hgylbxjfjfxqbbb_dt2 where mainid="+"(select id from uf_hgylbxjfjfxqbbb where requestid=" + requestid+")"; //获取明细条2
        }
        log.info("海关医疗保险缴费经费明细表sql:--->"+StrSQL);
        rs.executeQuery(StrSQL);
        return rs;
    }
}
